<template>
  <div class="show-code">
    <!-- <header-bar
      v-if="!$route.meta.hideHeader"
      ref="header"
      :title="title"
    >
      <template v-if="$store.state.user.show" />
    </header-bar>-->
    <div ref="content" class="order-content">
      <div class="mixing-station message message-title">
        <div class="icon-title van-cell order-title">
          <svg-icon icon-class="user" class="icon-class" />
          <span class="icon-title-content">基本信息</span>
        </div>
        <div class="content-person">
          <van-radio-group v-model="person.type" direction="horizontal">
            <van-radio :name="1">正常人群</van-radio>
            <van-radio :name="2">异常人群</van-radio>
          </van-radio-group>
        </div>
        <van-field
          v-model="person.name"
          label="姓名"
          placeholder="请输入姓名"
          required
        />
        <van-cell class="van-cell--required van-field van-field--error" :value="getCard(person.certificateType)" title="证件类型" is-link @click="getCardType" />
        <van-field
          v-model="person.cardNum"
          label="证件号码"
          placeholder="请输入证件号码(身份证，护照等)"
          required
          @input="getCardNum"
        />
        <van-field
          v-model="person.phone"
          label="手机号码"
          placeholder="请输入联系电话"
          type="number"
          required
        />
        <van-cell class="van-cell--required van-field van-field--error" :value="person.national" title="国籍" is-link @click="getNation" />
        <van-cell class="van-cell--required van-field van-field--error" :value="person.address" title="居住地区" is-link @click="getChioocePlace(1)" />
        <van-field
          v-model="person.addressDetail"
          label="详细地址"
          placeholder="详细地址"
          :required="true"
        />
      </div>
      <div class="mixing-station messages">
        <div class="icon-title van-cell order-title">
          <svg-icon icon-class="yiqing" class="icon-class" />
          <span class="icon-title-content">隔离信息</span>
        </div>
        <van-field
          v-model="person.quarantCounty"
          required
          label="隔离点所属辖区"
          placeholder="请输入隔离点所属辖区"
          disabled
        />
        <van-field
          v-model="person.quarantAddress"
          required
          label="集中隔离点名称"
          placeholder="请输入集中隔离点"
          disabled
        />

        <van-cell class="van-cell--required van-field van-field--error" title="隔离开始时间" :value="person.startTime" is-link @click="getime(1)" />
        <van-cell v-if="state.toString()==='1'" class="van-cell--required van-field van-field--error" title="预计解除隔离时间" :value="person.endTime" is-link @click="getime(2)" />
        <van-cell v-else-if="state.toString()==='0'" class="van-cell--required van-field van-field--error" title="预计解除隔离时间" :value="person.endTime" is-link @click="getime(2)" />
        <van-cell v-else class="van-cell--required van-field van-field--error" title="实际解除隔离时间" :class="[(state.toString()==='0')?'stop-update':'']" :value="person.realTime" is-link />
        <van-cell class="van-cell--required van-field van-field--error" :value="quarantReason" title="隔离原因" is-link @click="changeLocation" />
        <van-cell class="van-cell--required van-cell--requiredvan-field van-field--error" title="来源省市" :value="person.fromArea" is-link @click="getChioocePlace(2)" />
        <van-cell v-if="showLocal" class="van-cell--required van-cell--requiredvan-field van-field--error" title="是否市外转入">
          <!-- 使用 right-icon 插槽来自定义右侧图标 -->
          <template #right-icon>
            <van-radio-group v-model="person.isOutCity" direction="horizontal">
              <van-radio :name="1">是</van-radio>
              <van-radio :name="0">否</van-radio>
            </van-radio-group>
          </template>
        </van-cell>
        <van-cell v-if="person.isOutCity===1" class="van-cell--required van-field van-field--error" title="市外隔离开始时间" :value="person.outCityStartTime" is-link @click="getime(4)" />
        <van-cell v-if="person.isOutCity===1" class="van-cell--required van-field van-field--error" title="市外结束隔离时间" :value="person.outCityEndTime" is-link @click="getime(6)" />

        <van-cell class="van-cell--required van-cell--requiredvan-field van-field--error" title="是否转运">
          <!-- 使用 right-icon 插槽来自定义右侧图标 -->
          <template #right-icon>
            <van-radio-group v-model="person.isTransfer" direction="horizontal">
              <van-radio :name="1">是</van-radio>
              <van-radio :name="0">否</van-radio>
            </van-radio-group>
          </template>
        </van-cell>
        <van-cell v-if="person.isTransfer===1" class="van-cell--required van-cell--requiredvan-field van-field--error" title="转运省市" :value="person.transferCity" is-link @click="getChioocePlace(6)" />

        <van-cell v-if="showLocal" class="van-cell--required van-field van-field--error" title="意向去向区县" :value="person.wantGoName" is-link @click="getChioocePlace(3)" />
        <van-field
          v-if="showLocal"
          v-model="person.wantAddress"
          label="详细地址"
          placeholder="详细地址"
          :required="showLocal?true:false"
        />
        <van-field
          v-model="person.remark"
          rows="2"
          autosize
          label="备注"
          type="textarea"
          maxlength="50"
          placeholder="请输入备注"
          show-word-limit
        />
      </div>
      <div class="mixing-station message-are">
        <div class="icon-title van-cell order-title" style="display:flex;justify-content:space-between;align-items:center;">
          <div>
            <svg-icon icon-class="are" class="icon-class" />
            <span class="icon-title-content">核酸信息</span>
          </div>
          <div><svg-icon icon-class="add" class="icon-class" @click.native="addAre" /></div>
        </div>
        <van-cell
          v-for="(item,index) in arrAre"
          :key="index"
          class="van-field van-field--error"
          :title="item.title"
          :value="item.value"
          @click="getAre(index)"
        >
          <template #right-icon>
            <svg-icon v-if="index!==0" icon-class="delete" class="icon-class" @click.native.stop.prevent="deleteAre(index)" />
            <van-icon v-else name="arrow" size="15" color="#969799" />
          </template>
        </van-cell>
      </div>
      <!-- <div class="mixing-station">
        <van-field
          v-model="remark"
          rows="2"
          autosize
          label="备注"
          type="textarea"
          placeholder="请输入备注":disabled="state.toString()==='0'"
          show-word-limit
        />
      </div> -->
      <div class="content-info-submit">
        <van-button
          type="info"
          class="van-confirm confirm-message"
          style="margin-bottom:20px;"
          @click="submit"
        >{{ btnName }}</van-button>
      </div>

      <div style="width:100%;height:100px;" :class="[showTitlePaddingTop?'title-message':'']" />
    </div>

    <van-popup v-model="timeShow" position="bottom" :style="{ height: '50%' }">
      <van-area
        title="省市区"
        :area-list="locationIndex===6?areaArree:areaLists"
        :value="locationIndex===6?'510000':'500000'"
        @confirm="confirmAdress"
        @cancel="cancelAdress"
      />
    </van-popup>
    <van-popup v-model="timeShows" position="bottom" :style="{ height: '50%' }">
      <van-datetime-picker
        v-model="currentDate"
        type="datehour"
        title="选择时间"
        :min-date="minDate"
        :max-date="maxDate"
        @confirm="confirms"
        @cancel="cancels"
        @change="changeTime"
      />
    </van-popup>
    <van-popup v-model="changeShow" position="bottom" :style="{ height: '50%' }">
      <van-picker
        title="隔离原因"
        show-toolbar
        :columns="columnReson"
        @confirm="onConfirm"
        @cancel="onCancel"
      />
    </van-popup>
    <van-popup v-model="cardTypeStates" position="bottom" :style="{ height: '50%' }">
      <van-picker
        title="证件类型"
        show-toolbar
        :columns="cardTypeOption"
        @confirm="onConfirmCardType"
        @cancel="cardTypeStates=false"
      />
    </van-popup>
    <van-popup v-model="otherState" position="bottom" :style="{ height: '50%' }">
      <van-picker
        title="其它"
        show-toolbar
        :columns="columnOtherNation"
        @confirm="onConfirmOther"
        @cancel="onCancelOther"
      />
    </van-popup>

    <van-popup v-model="showAre" position="bottom" :style="{ height: '50%' }">
      <van-picker
        title="核酸检测结果"
        show-toolbar
        :columns="columnAre"
        @confirm="onConfirmAre"
        @cancel="showAre=false"
      />
    </van-popup>
    <van-dialog v-model="showCard" confirm-button-text="继续录入" title="实名认证信息" show-cancel-button @confirm="confirmRemove">
      <!-- <div class="remove-time">{{ dateFormat("YYYY-mm-dd HH:MM:SS", new Date()) }}</div> -->
      <div class="wrapper-content" style="display:flex;justify-content:center;">
        {{ info }}
      </div>
    </van-dialog>
  </div>
</template>
<script>
// import { areaList } from '@vant/area-data'
import Vue from 'vue'
import { Switch, Cell, Field, Collapse, CollapseItem, Toast, Icon, Picker, Popup, DatetimePicker, CellGroup, Dialog } from 'vant'
Vue.use(Switch).use(Cell).use(Field).use(Collapse).use(CollapseItem).use(Icon).use(Picker).use(Popup).use(DatetimePicker).use(CellGroup).use(Dialog).use(Toast)
import { Button } from 'vant'
import { Area } from 'vant'
import { RadioGroup, Radio } from 'vant'

Vue.use(Radio)
Vue.use(RadioGroup)
Vue.use(Area)
Vue.use(Button)
import $api from '@/api/index'
import { checkPhone } from '@/utils/validate'
import { mapGetters } from 'vuex'
import { areaList } from '@/utils/locationmsg'
import { areaArre } from '@/utils/locationArea'
export default {
  name: 'ShowCode',
  data() {
    return {
      person: {
        name: '',
        phone: '',
        cardNum: '',
        address: '请选择居住地址',
        quarantCounty: '',
        quarantAddress: '', // 请选择隔离开始时间
        startTime: this.timeFormat(new Date()),
        endTime: this.timeFormat(new Date(), 1),
        outCityStartTime: this.timeFormat(new Date(), 2),
        outCityEndTime: this.timeFormat(new Date(), 4),
        quarantReason: '',
        fromArea: '请选择来源省市',
        national: '中国',
        acidResult: [],
        quarantReasonValue: '',
        remark: '',
        type: 1,
        certificateType: '111',
        wantGo: '',
        wantGoName: '',
        wantAddress: '',
        transferCity: '请选择转运省市',
        isTransfer: 0,
        isOutCity: 0,
        addressDetail: ''

      },
      remark: '',
      num: '',
      timeShow: false,
      timeShows: false,
      timeEndShows: false,
      minDate: new Date(2020, 0, 1),
      maxDate: new Date(2025, 10, 1),
      areaLists: areaList,
      areaArree: areaArre,
      id: '',
      title: '采集隔离人员信息',
      btnName: '确认录入',
      currentDate: '',
      endDate: this.$moment('2021/09/03 15:00:00').add(1, 'days').toDate(),
      show: true,
      changeShow: false,
      columnReson: [],
      quarantReason: '请选择隔离原因',
      state: '0',
      locationIndex: '',
      arrAre: [{ title: '第一次核酸检测结果', value: '请选择', id: '' }],
      numArr: ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十'],
      showAre: false,
      columnAre: [{ text: '阴性', id: '0' }, { text: '阳性', id: '1' }],
      areIndex: '',
      areObj: {},
      showNation: false,
      otherState: false,
      columnOtherNation: [{ text: '其它国家', id: '0' }],
      cardTypeOption: [
        { text: '公民身份证', id: '111' },
        { text: '中国人民解放军军官证编号', id: '114' },
        { text: '中国人民武装警察部队警官证编号', id: '115' },
        { text: '中国人民解放军士兵证编号', id: '118' },
        { text: '中国人民武装警察部队士兵证编号', id: '119' },
        { text: '中国人民解放军文职人员证编号', id: '120' },
        { text: '中国人民解放军武装警察部队文职人员证编号', id: '122' },
        { text: '护照号', id: '400' },
        { text: '海员证', id: '419' },
        { text: '台湾居民来往内地通行证号码', id: '511' },
        { text: '台湾居民居住证', id: '552' },
        { text: '港澳居民来往内地通行证号码', id: '516' },
        { text: '港澳居民居住证', id: '551' },
        { text: '其他自然人有效证件代码', id: '999' }],
      arrQuarant: ['28daysQuarantine', '21daysQuarantine', '14daysQuarantine', 'Patientsentryfield', '7daysQuarantine', 'InternationalFlightCrew', 'LightToChongqing'],
      otherNationFromAre: false,
      quarantState: false,
      arrFromArea: ['28daysQuarantine', '21daysQuarantine', '14daysQuarantine', 'HighRiskArea'],
      cardTypeStates: false,
      showCard: false,
      info: ''
    }
  },
  computed: {
    ...mapGetters([
      'reportId',
      'reportName',
      'parentName',
      'createId',
      'nation',
      'location'
    ]),
    showTitlePaddingTop() {
      return this.$store.state.user.showTitlePaddingTop
    },
    showLocal() {
      return this.arrQuarant.indexOf(this.person.quarantReasonValue) > -1
    }
  },
  beforeRouteLeave(to, from, next) {
    if (to.path === '/applicationcode/index' || to.path === '/distance/index') {
      this.$store.dispatch('user/delView', this.$route.name)
      if (this.show) { // 钉钉头部返回页面缓存
        this.$store.dispatch('user/refresh', false)
      }
    }
    if (to.path === '/nation/index') {
      this.$store.dispatch('user/showView', this.$route.name)
      console.log(this.$store)
    }
    if (to.path === '/laction/index') {
      this.$store.dispatch('user/showView', this.$route.name)
      console.log(this.$store)
    }
    next()
  },
  watch: {
    'person.national'(newValue, oldValue) {
      if (newValue !== '中国') {
        this.person.address = '其它国家'
      } else {
        this.person.address = '请选择居住地址'
      }
    }
    // 'person.dictValue'(newValue, oldValue) {
    //   this.person.fromArea = '请选择始发地'
    // }
  },
  beforeCreate() {
    this.$dd.hideTitleBar()
    this.$dd.showTitleBar()
  },
  activated() {
    this.$dd.hideTitleBar()
    this.$dd.showTitleBar()

    if (this.nation) {
      this.person.national = this.nation
    } else {
      this.person.national = '中国'
    }
    if (this.location) {
      this.person.fromArea = this.location
    }
    this.$dd.ready(() => {
      this.$dd.setTitle({
        title: this.$route.query.id ? '修改隔离人员信息' : '采集隔离人员信息'
      })
    })
  },
  mounted() {
    // var arr = []
    // for (var i = 0; i < geolocation.length; i++) {
    //   for (var j = 0; j < geolocation[i].length; j++) {
    //     arr.push({ text: geolocation[i][1], id: geolocation[i][0] })
    //   }
    // }
    // console.log(JSON.stringify(areaList))
    this.$dd.hideTitleBar()
    this.$dd.showTitleBar()

    this.person.quarantAddress = this.reportName
    try {
      this.person.quarantCounty = this.parentName.split('集中')[0]
    } catch (error) {
      Toast('辖区名称解析失败!')
    }
    this.list()
    this.$dd.ready(() => {
      this.$dd.setTitle({
        title: this.$route.query.id ? '修改隔离人员信息' : '采集隔离人员信息'
      })
    })

    if (this.$until.h5userAgent() === 1) {
      this.$store.dispatch('user/showTitle', true)
    }
    if (this.$route.query.obj) {
      const obj = JSON.parse(this.$route.query.obj)
      this.person.name = obj.name
      this.person.phone = obj.mobile
      this.person.cardNum = obj.cardNo
    }
    if (this.$route.query.id) {
      this.id = this.$route.query.id
      this.state = this.$route.query.state
      this.quarantineDetail()
      this.title = '修改隔离人员信息'
      this.btnName = '确认修改'
    } else {
      this.state = this.$route.query.state
      this.title = '采集隔离人员信息'
      this.btnName = '确认录入'
    }
  },
  beforeDestroy() {
    this.$dd.hideTitleBar()
  },
  destroyed() {
    this.$dd.hideTitleBar()
  },
  methods: {
    goback() {

    },
    saveInfo() {
      if (!this.person.name) {
        Toast('姓名不能为空')
        return
      }
      if (!this.person.phone) {
        Toast('手机号码不能为空')
        return
      }
      if (!checkPhone(this.person.phone)) {
        Toast('手机号码格式错误!')
        return
      }
      if (!this.person.cardNum) {
        Toast('证件号码不能为空')
        return
      }

      if (!this.person.quarantCounty) {
        Toast('隔离点所属辖区不能为空')
        return
      }
      if (this.person.address === '请选择居住地址') {
        Toast('居住地址不能为空')
        return
      }
      if (this.person.fromArea === '请选择来源省市') {
        Toast('请选择来源省市')
        return
      }
      if (this.showLocal) {
        if (!this.person.wantGo) {
          Toast('请选择意向地址')
          return
        }
        if (!this.person.wantAddress) {
          Toast('请输入详细地址')
          return
        }
      }
      if (!this.person.addressDetail) {
        Toast('请输入详细地址')
        return
      }

      if (this.person.isTransfer === 1) {
        if (this.person.transferCity === '请选择转运省市') {
          Toast('选择转运省市')
          return
        }
      }
      if (this.person.isTransfer === 0) {
        this.person.transferCity = ''
      }

      // if (this.person.national === '中国' && this.person.address.indexOf('台湾') === -1 && this.person.address.indexOf('香港') === -1 && this.person.address.indexOf('澳门') === -1) {
      //   var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/
      //   if (reg.test(this.person.cardNum) === false) {
      //     Toast('身份证输入不合法')
      //     return
      //   }
      // }
      if (this.person.certificateType === '请选择证件类型') {
        Toast('证件类型不能为空')
        return
      }
      if (this.person.certificateType === '111') {
        var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/
        if (reg.test(this.person.cardNum) === false) {
          Toast('身份证输入不合法')
          return
        }
      }
      if (!this.person.quarantAddress) {
        Toast('集中隔离点不能为空')
        return
      }
      if (this.person.startTime === '请选择隔离开始时间') {
        Toast('开始隔离时间不能为空')
        return
      }
      if (this.person.endTime === '请选择预计解除隔离时间') {
        Toast('预计解除隔离时间不能为空')
        return
      }
      if (!this.person.quarantReason) {
        Toast('隔离原因不能为空')
        return
      }
      if (new Date(`${this.person.startTime}:00:00`).getTime() > new Date(`${this.person.endTime}:00:00`).getTime()) {
        Toast('预计解除隔离时间不能小于隔离开始时间')
        return
      }
      // if (this.person.startTime.split('-')[0] > this.person.endTime.split('-')[0]) {

      // }
      if (this.person.fromArea === '请选择来源省市') {
        this.person.fromArea = '其它'
      }
      if (this.person.isOutCity === 0) {
        this.person.outCityStartTime = ''
        this.person.outCityEndTime = ''
      }
      this.person.acidResult = []
      this.person['createId'] = this.createId
      this.person['updateId'] = this.createId
      this.person['reportId'] = this.reportId
      this.person.cardNum = this.person.cardNum.toUpperCase()
      this.arrAre.forEach(res => {
        if (res.id) {
          (res.id === '0' || res.id === '1') ? this.person.acidResult.push(res) : ''
        }
      })
      if (this.person.acidResult.length !== 0) {
        this.person.acidResult = JSON.stringify(this.person.acidResult)
      } else {
        this.person.acidResult = ''
      }
      $api.user.checkCardNum(this.person).then(re => {
        $api.user.saveInfo(this.person).then(res => {
          this.show = false
          this.$store.dispatch('user/delView', this.$route.name)
          this.$store.dispatch('user/refresh', true)
          this.$store.dispatch('user/delView', 'Applicationcode')
          this.$router.go(-1)
        }, error => {
          Toast(error.data ? error.data : '操作失败,请稍候重试!')
        })
      }, err => {
        Toast.clear()
        this.info = err.data
        this.showCard = true
      })
    },
    confirmRemove() {
      $api.user.saveInfo(this.person).then(res => {
        this.show = false
        this.$store.dispatch('user/delView', this.$route.name)
        this.$store.dispatch('user/refresh', true)
        this.$store.dispatch('user/delView', 'Applicationcode')
        this.$router.go(-1)
      }, error => {
        Toast(error.data ? error.data : '操作失败,请稍候重试!')
      })
    },
    getCardNum(val) {
      this.person.cardNum = val.replace(/[^\a-\z\A-\Z0-9]/g, '')
    },
    getChioocePlace(index) {
      this.locationIndex = index
      if (index === 1 && this.person.national !== '中国') {
        // this.otherState = true

      } else if (index === 2 && this.person.quarantReasonValue && this.arrQuarant.indexOf(this.person.quarantReasonValue) > -1) {
        this.$router.push({ path: '/laction/index' })
      } else {
        this.timeShow = true
      }
    },
    onConfirmOther(val) {
      this.person.address = val.text
      this.otherState = false
    },
    onCancelOther() {
      this.otherState = false
    },
    getime(num) {
      this.num = num

      if (this.state.toString() === '0' && this.num === 2) {
        return
      }
      this.num === 1 ? this.currentDate = this.$moment(this.person.startTime).toDate() : this.currentDate = this.$moment(this.person.endTime).toDate()
      if (this.num === 1) {
        this.currentDate = this.$moment(this.person.startTime).toDate()
      } else if (this.num === 2) {
        this.currentDate = this.$moment(this.person.endTime).toDate()
      } else if (this.num === 4) {
        this.currentDate = this.$moment(this.person.outCityStartTime).toDate()
      } else if (this.num === 6) {
        this.currentDate = this.$moment(this.person.outCityEndTime).toDate()
      }
      this.timeShows = true
    },
    confirms(value) {
      if (this.num === 1) {
        this.person.startTime = this.timeFormat(value)
      } else if (this.num === 2) {
        this.person.endTime = this.timeFormat(value)
      } else if (this.num === 4) {
        this.person.outCityStartTime = this.timeFormat(value)
      } else if (this.num === 6) {
        this.person.outCityEndTime = this.timeFormat(value)
      }
      this.timeShows = false
    },
    cancels() {
      this.timeShows = false
      this.timeEndShows = false
    },
    timeFormat(time, arg) { // 时间格式化 2019-09-08
      let year = time.getFullYear()

      let month = time.getMonth() + 1
      let day = ''
      if (!arg) {
        day = time.getDate() < 10 ? '0' + time.getDate() : time.getDate()
      } else if (arg === 2) {
        day = time.getDate() < 10 ? '0' + (time.getDate() - 2) : (time.getDate() - 2)
      } else if (arg === 4) {
        day = time.getDate() < 10 ? '0' + (time.getDate() - 1) : (time.getDate() - 1)
      } else {
        day = time.getDate() < 10 ? '0' + (time.getDate() + 1) : (time.getDate() + 1)
        if ((month === 1 || month === 3 || month === 5 || month === 7 || month === 8 || month === 10 || month === 12) && time.getDate() === 31) {
          if (month === 12) {
            year += 1
            day = '01'
            month = 1
          } else {
            month += 1
            day = '01'
          }
        } else if ((month === 4 || month === 6 || month === 9 || month === 11) && time.getDate() === 30) {
          month += 1
          day = '01'
        } else if ((month === 2) && time.getDate() === 28) {
          month += 1
          day = '01'
        } else {
          day = time.getDate() < 10 ? '0' + time.getDate() + 1 : time.getDate() + 1
        }
      }

      const hours = time.getHours() < 10 ? '0' + time.getHours() : time.getHours()
      // const minutes = time.getMinutes() < 10 ? '0' + time.getMinutes() : time.getMinutes()
      if (month < 10) {
        return year + '-' + '0' + month + '-' + day + ' ' + hours
      } else {
        return year + '-' + month + '-' + day + ' ' + hours
      }
    },
    getCard(val) {
      let card = ''
      card = this.cardTypeOption.filter(item => {
        return val === item.id
      })
      return card[0].text
    },
    submit() {
      if (this.id) {
        this.updateInfo()
      } else {
        this.saveInfo()
      }
    },
    quarantineDetail() {
      $api.user.quarantineDetail({ id: this.id, createId: this.createId }).then(res => {
        this.person = res.data
        this.person.startTime = res.data.startTime
        this.person.endTime = res.data.endTime
        if (this.person.acidResult) {
          this.arrAre = JSON.parse(this.person.acidResult)
        }
        this.quarantReason = this.person.quarantReason
        !this.person.transferCity ? this.person.transferCity = '请选择转运省市' : ''
        !res.data.outCityStartTime ? this.person.outCityStartTime = this.timeFormat(new Date(), 2) : this.person.outCityStartTime = res.data.outCityStartTime
        !res.data.outCityEndTime ? this.person.outCityEndTime = this.timeFormat(new Date(), 4) : this.person.outCityEndTime = res.data.outCityEndTime
      })
    },
    updateInfo() {
      // if (this.state.toString() === '0') {
      //   Toast('不能修改解除隔离人员信息')
      //   return
      // }
      if (!this.person.name) {
        Toast('姓名不能为空')
        return
      }
      if (!this.person.phone) {
        Toast('手机号码不能为空')
        return
      }
      if (!checkPhone(this.person.phone)) {
        Toast('手机号码格式错误!')
        return
      }
      if (!this.person.cardNum) {
        Toast('证件号码不能为空')
        return
      }

      if (!this.person.quarantCounty) {
        Toast('隔离点所属辖区不能为空')
        return
      }
      if (this.person.address === '请选择居住地址') {
        Toast('居住地址不能为空')
        return
      }
      if (this.person.fromArea === '请选择来源省市') {
        Toast('请选择来源省市')
        return
      }
      if (this.person.certificateType === '111') {
        var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/
        if (reg.test(this.person.cardNum) === false) {
          Toast('身份证输入不合法')
          return
        }
      }
      if (!this.person.quarantAddress) {
        Toast('集中隔离点不能为空')
        return
      }
      if (this.person.startTime === '请选择隔离开始时间') {
        Toast('开始隔离时间不能为空')
        return
      }
      if (this.person.endTime === '请选择预计解除隔离时间') {
        Toast('预计解除隔离时间不能为空')
        return
      }
      if (!this.person.quarantReason) {
        Toast('隔离原因不能为空')
        return
      }
      if (this.showLocal) {
        if (!this.person.wantGo) {
          Toast('请选择意向地址')
          return
        }
        if (!this.person.wantAddress) {
          Toast('请输入详细地址')
          return
        }
      }
      if (!this.person.addressDetail) {
        Toast('请输入详细地址')
        return
      }
      if (this.person.isTransfer === 1) {
        if (this.person.transferCity === '请选择转运省市') {
          Toast('选择转运省市')
          return
        }
      }
      if (this.person.isOutCity === 0) {
        this.person.outCityStartTime = ''
        this.person.outCityEndTime = ''
      }
      if (this.person.isTransfer === 0) {
        this.person.transferCity = ''
      }
      this.person.acidResult = []
      this.person['id'] = this.id
      this.person['createId'] = this.createId
      this.person['reportId'] = this.reportId
      this.person.cardNum = this.person.cardNum.toUpperCase()
      if (this.person.realTime) {
        if (new Date(`${this.person.startTime}:00:00`).getTime() > new Date(this.person.realTime).getTime()) {
          Toast('隔离开始时间不能大于实际解除隔离时间')
          return
        }
      } else {
        if (new Date(`${this.person.startTime}:00:00`).getTime() > new Date(`${this.person.endTime}:00:00`).getTime()) {
          Toast('隔离开始时间不能大于预计解除隔离时间')
          return
        }
      }

      this.arrAre.forEach(res => {
        (res.id === '0' || res.id === '1') ? this.person.acidResult.push(res) : ''
      })
      if (this.person.acidResult.length !== 0) {
        this.person.acidResult = JSON.stringify(this.person.acidResult)
      } else {
        this.person.acidResult = ''
      }
      $api.user.updateInfo(this.person).then(res => {
        this.show = false
        this.$store.dispatch('user/refresh', true)
        sessionStorage.setItem('keepAlive', true)// 修改返回更新数据
        this.person = res.data
        this.$router.go(-1)
      })
    },
    confirmAdress(arg) {
      this.locationIndex === 1 ? this.person.address = '' : this.locationIndex === 2 ? this.person.fromArea = '' : this.locationIndex === 3 ? this.person.wantGoName = '' : this.person.transferCity = ''

      const arr = []
      arg.forEach(res => {
        arr.push(res.name)
      })
      if (this.showLocal) {
        this.person.wantGo = arg[arg.length - 1].code
      }
      this.locationIndex === 1 ? this.person.address = arr.join('-') : this.locationIndex === 2 ? this.person.fromArea = arr.join('-') : this.locationIndex === 3 ? this.person.wantGoName = arr.join('-') : this.person.transferCity = arr.join('-')
      this.timeShow = false
    },
    cancelAdress() {
      this.timeShow = false
    },
    list() {
      this.columnReson = []
      $api.user.list({ dictType: 'Isolate' }).then(res => {
        res.data.forEach(res => {
          this.columnReson.push({ text: res.dictLabel, id: res.dictValue })
        })
      })
    },
    changeLocation() {
      // if (this.state.toString() === '0') {
      //   return
      // }
      this.changeShow = true
    },
    onConfirm(value, index) {
      this.quarantReason = value.text
      this.person.quarantReason = value.text
      this.person.quarantReasonValue = value.id
      // if (this.person.dictValue && this.arrQuarant.indexOf(this.person.dictValue) > -1) {
      //   this.person.fromArea = '请选择始发地'
      // }
      this.person.fromArea = '请选择来源省市'
      this.changeShow = false
    },
    onCancel() {
      this.changeShow = false
    },
    onChangeLocation() {},
    getAre(index) {
      this.areIndex = index
      this.showAre = true
    },
    getCardType() {
      this.cardTypeStates = true
    },
    onConfirmCardType(value, index) {
      this.person.certificateType = value.id
      this.cardTypeStates = false
    },
    onConfirmAre(value, index) {
      this.arrAre[this.areIndex].value = value.text
      this.arrAre[this.areIndex].id = value.id
      this.showAre = false
    },
    onCancelAre() {},
    addAre() {
      let state = false
      this.arrAre.forEach(res => {
        if (!res.id) {
          state = true
          Toast('请先选择核酸结果')
        }
      })
      if (state) {
        return
      }
      if (this.arrAre.length === 9) {
        Toast('暂未开放更多选项')
        return
      }
      this.arrAre.push({ title: `第${this.numArr[this.arrAre.length]}次核酸检测结果`, value: '请选择', id: '' })
    },
    deleteAre(index) {
      this.arrAre.splice(index, 1)
      this.arrAre.forEach((res, i) => {
        if (i >= index) {
          this.$set(res, 'title', `第${this.numArr[i]}次核酸检测结果`)
        }
      })
    },
    getNation() {
      // this.showNation = true
      this.$router.push({ path: '/nation/index' })
    },
    onConfirmNation(val) {
      this.person.national = val.text
      this.showNation = false
    },
    onCancelNation() {
      this.showNation = false
    },
    changeTime(val) {
      // const time = val.split('/')
      console.log(val)
    }
  }
}
</script>
<style lang="scss" scoped>
.show-code{
    width:100%;
    height:100%;

    .order-content{
        width:100%;
        height:100%;
        overflow-y: scroll;
        background-color:#f7f8fa;
        font-family: PingFangSC-Regular, PingFang SC;
    }
}
.mixing-station{
    background-color: #ffffff;
    padding:0px 10px;
    margin-top:20px;
}
.icon-class{
  width:40px;
  height:40px;
}
.order-title{
    padding: 20px 30px;
}

.content-info-submit{
  display:flex;
  align-items:center;
  justify-content:center;
  padding-top:44px;
  width:660px;
  height:88px;
  margin:0 auto;
}
::v-deep .van-button__text{
  font-weight:500;
  font-size:32px;
}
.title-message{
  padding-top:80px;
}
.van-confirm{
  width:100%;
  height:100%;
  border-radius:10px;
  box-shadow: 5px 3px 15px 0px rgba(42, 102, 234, 0.56);
}
::v-deep .van-cell:not(:last-child)::after{
    position: absolute;
    box-sizing: border-box;
    content: ' ';
    pointer-events: none;
    right: 20px;
    bottom: 0;
    left: 20px;
    border-bottom: 1px solid #ebedf0;
    -webkit-transform: scaleY(.5);
    -ms-transform: scaleY(.5);
    transform: scaleY(.5);
}
.icon-title{
    display: flex;
    align-items: center;
}
.icon-title-content{
    padding-left: 20px;
    color: #333333;
    font-weight: Bold;
    font-size: 32px;
}
.mixing-station:not(:first-child){
    margin-top: 20px;
}
::v-deep .van-cell__title{
    width: 250px;
    flex:none;
    color:#646566;
    font-size:28px;
    padding-right:15px;
}
.message-title{
  ::v-deep .van-cell__title{
    width: 200px;
    flex:none;
    color:#646566;
    font-size:28px;
    padding-right:15px;
  }
}
.message-are{
  ::v-deep .van-cell__title{
    width: 250px;
    flex:none;
    color:#646566;
    font-size:28px;
    padding-right:15px;
  }
}
::v-deep .van-cell__value{
    text-align: left;
    flex:2;
    font-size:28px;
    color:#323233;
    // color: #323233;
}
::v-deep .chioce-mix{
    .van-cell__title{
        flex: 1;
    }
}
::v-deep [class*=van-hairline]::after{
    border: 0;
}
::v-deep .van-collapse-item__content{
    padding: 0;
}
::v-deep .van-collapse-item__title .van-cell__right-icon::before{
    -webkit-transform: rotate(0deg);
    -ms-transform: rotate(0deg);
    transform: rotate(0deg);
    -webkit-transition: -webkit-transform .3s;
    transition: -webkit-transform .3s;
    transition: transform .3s;
    transition: transform .3s, -webkit-transform .3s;
    transition: transform .3s,-webkit-transform .3s;
}
::v-deep .station{
    .van-cell__title{
        flex:1;
    }
}

 .message {
    ::v-deep .van-field__label {
      -webkit-box-flex: 0;
      -webkit-flex: none;
      -ms-flex: none;
      flex: none;
      box-sizing: border-box;
      width: 200px;
      margin-right: 16px;
      color: #646566;
      text-align: left;
      word-wrap: break-word;
  }
}
.messages{
  ::v-deep .van-field__label {
      -webkit-box-flex: 0;
      -webkit-flex: none;
      -ms-flex: none;
      flex: none;
      box-sizing: border-box;
      width: 250px;
      margin-right: 16px;
      color: #646566;
      text-align: left;
      word-wrap: break-word;
  }
}
.test .van-cell__value{
    display: flex;
    align-items:center;
}

.tests .van-cell__value{
    display: flex;
    align-items:center;
    position:relative;
}
.stop-update ::v-deep .van-cell__value{
    color:#969799;
  }
  .message-are{
    ::v-deep .van-cell__title{
      width: 270px;
    }
  }
  .content-person{
    padding:40px 20px;
    font-size:28px;
    color:#646566;
  }
  .wrapper-content{
  padding:20px 62.0px 20px 62.0px;
  text-align:center;
}
</style>
